package mongo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;

/**
 * Created by infi.he on 2015/9/23.
 */
public class Delete7MImg {
    public static void main(String[] args) throws Exception {
                List<Map> mapList = new ArrayList<>();


        String tableName = "adresourcestatsbyday";
        DB mongoDBClient = new MongoClient("10.2.35.16").getDB("cstore");

        System.out.println(mongoDBClient.getCollectionNames());
        DBCollection c = mongoDBClient.getCollection(tableName);

        DBObject matchObject = new BasicDBObject();
//        matchObject.put("orgId", 2);
        matchObject.put("day", "1970-01-01");
        DBCursor cursor = c.find(matchObject);
        System.out.println(cursor.count());
//
//
//
//        while (cursor.hasNext()) {
//            DBObject dbObject = cursor.next();
//            mapList.add(dbObject.toMap());
//        }
//
//        cursor.close();
//
//
//        for (Map map : mapList) {
//            String mongodbId = map.get("mongodbId").toString();
//            String visitPath = map.get("visitPath").toString();
//
//            URL httpUrl = new URL(visitPath);
//            URLConnection urlConnection = httpUrl.openConnection();
//            urlConnection.setConnectTimeout(CommonConstants.HTTP_CONNECTION_TIME_OUT);
//            urlConnection.setReadTimeout(CommonConstants.HTTP_READ_TIME_OUT);
//            InputStream inputStream = urlConnection.getInputStream();
//
//            byte[] bs = new byte[1024];
//            int len;
//            FileOutputStream os = new FileOutputStream("tmp.tmp");
//
//            // 开始读取
//            while ((len = inputStream.read(bs)) != -1) {
//                os.write(bs, 0, len);
//            }
//            System.out.println("mongodbId   "+mongodbId+" ; "+ "size "+os.getChannel().position());
//
//            // 完毕，关闭所有链接
//            os.close();
//            inputStream.close();
//        }
    }
}
